import { merge } from "lodash-es";
import { $http } from "../boot/http";
import { mapStore } from "../utils/store";

export default merge(
  {
    namespaced: true,
    state: {},
    mutations: {},
    getters: {},
    actions: {
      async getAnnouncementById({ dispatch }, id) {
        return dispatch(
          "toggleLoading",
          {
            key: "announcement.getById",
            loading: async () => {
              const { data } = await $http.get("/api/v1/announce/" + id);
              return data;
            }
          },
          { root: true }
        );
      }
    }
  },
  mapStore("announcement", {
    url: "api/v1/announce",
    options: {
      actionOptions: { commitType: "page", cacheState: false }
    }
  })
);
